package com.zhz.confirm;

import com.rabbitmq.client.*;
import com.zhz.utils.RabbitConstant;
import com.zhz.utils.RabbitUtils;

import java.io.IOException;

/**
 * 
 * @date ：Created in 2021/02/04
 * @version: V1.0
 * @slogan: 天下风云出我辈，一入代码岁月催
 * @description: 消费者
 **/
public class Sina {
    public static void main(String[] args) throws IOException {
        Connection connection = RabbitUtils.getConnection();
        Channel channel = connection.createChannel();
        channel.queueDeclare(RabbitConstant.QUEUE_SINA,false,false,false,null);
        channel.queueBind(RabbitConstant.QUEUE_SINA,RabbitConstant.EXCHANGE_WEATHER_TOPIC,"us.#");
        channel.basicQos(1);
        channel.basicConsume(RabbitConstant.QUEUE_SINA,false,new DefaultConsumer(channel){
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println("新浪收到的天气预报："+new String(body));
                channel.basicAck(envelope.getDeliveryTag(),false);
            }
        });
    }
}
